import Vue from "vue";
import Router from "vue-router";
import Live from "@/pages/Live";
import Jpeg from "@/pages/Jpeg";

Vue.use(Router);

const VueRouterPush = Router.prototype.push;
Router.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch((err) => err);
};

const router = new Router({
  routes: [
    {
      name: "index",
      path: "/",
      component: Jpeg,
      meta: {
        title: "视频",
      },
    },
    {
      name: "jpeg",
      path: "/live",
      component: Live,
      meta: {
        title: "视频",
      },
    },
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      // savedPosition 当且仅当 popstate 导航 (通过浏览器的 前进/后退 按钮触发) 时才可用。
      return savedPosition;
    } else {
      return {
        x: 0,
        y: 0,
      };
    }
  },
});

export default router;
